<template>
  <div>
     <Row>
        <input v-model="userId" placeholder="玩家Id" ></input>
        <input v-model="userName" placeholder="玩家名字" ></input>
        <Button type="primary" @click="onSearch">查询</Button>
    </Row>
    <Table :border="true" :stripe="true" :show-header="false"  :data="tableData" :columns="tableColumns"></Table>
    <Modal
        title="充值详情"
        v-model="rechargeModal" :width="1600" :height="1000">
        <Table :border="true" :stripe="true" :show-header="true"  :data="rechargeData" :columns="rechargeColumns" ></Table>
        <Page class="bottom-page" :total="totalPage" :current="crtPage" :page-size="pageSize" show-total show-elevator @on-change="onChange"></Page>
    </Modal>
  </div>
</template>
<script>

import {getRoleBaseInfo, getRechargeLogs} from '@/api/game.js'
import {getVO} from '@/common/proto-vo.js'
export default {
  data () {
    return {
      userId: '',
      userName: '',
      crtPage: 1,
      totalPage: 0,
      pageSize: 20,
      tableData: [],
      rechargeData: [],
      rechargeModal: false,
      selectUserId: ''
    }
  },
  created () {
    // this.onSearch()
  },
  methods: {
    onSearch () {
      console.log('userId:', this.userId, ',userName:')
      getRoleBaseInfo(this.userId, this.userName).then((data) => {
        if (!data) {
          return
        }
        this.tableData = []
        let RoleBaseInfoVO = getVO('RoleBaseInfoVO')
        let pv = data.data.data
        let len = pv.data.length
        for (let i = 0; i < len; i++) {
          let vo = RoleBaseInfoVO.decode(pv.data[i])
          this.selectUserId = vo.userId
          this.tableData.push({
            name: '数字id', val: vo.id.toNumber()
          })
          this.tableData.push({
            name: '玩家id', val: vo.userId
          })
          this.tableData.push({
            name: '玩家名字', val: vo.userName
          })
          this.tableData.push({
            name: '版本号', val: vo.versionCode
          })
          this.tableData.push({
            name: '是否在线', val: vo.isOnline
          })
          this.tableData.push({
            name: '账号状态', val: vo.status
          })
          this.tableData.push({
            name: '注册ip', val: vo.ipAddress
          })
          this.tableData.push({
            name: '最后登录ip', val: vo.lastOnLineIP
          })
          this.tableData.push({
            name: '注册时间', val: vo.createTime.toNumber()
          })
          this.tableData.push({
            name: '等级', val: vo.level
          })
          this.tableData.push({
            name: '等级经验', val: vo.levelPoint.toNumber()
          })
          this.tableData.push({
            name: 'vip', val: vo.vip
          })
          this.tableData.push({
            name: 'vip经验', val: vo.vipPoint.toNumber()
          })
          this.tableData.push({
            name: '金币', val: vo.points.toNumber()
          })
          this.tableData.push({
            name: '充值总额', val: vo.chregePoints.toNumber()
          })
          this.tableData.push({
            name: '渠道号', val: vo.business
          })
          this.tableData.push({
            name: '运营商', val: vo.gameOperator
          })
          this.tableData.push({
            name: '硬件', val: vo.hardware
          })
          this.tableData.push({
            name: '设备号', val: vo.imieId
          })
          this.tableData.push({
            name: '手机', val: vo.mobile
          })
          this.tableData.push({
            name: 'facebook', val: vo.facebookId
          })
          this.tableData.push({
            name: '最后登录时间', val: vo.lastOnLineTime.toNumber()
          })
          this.tableData.push({
            name: '登录天数', val: vo.loginDay
          })
          this.tableData.push({
            name: '持续登录天数', val: vo.continueLoginDay
          })
          this.tableData.push({
            name: '最大连续登陆次数', val: vo.bigContinueLoginDay
          })
        }

        console.log(this.tableData)
      })
    },
    onChange (item) {
      console.log(item)
      this.crtPage = item
      this.handleRechargeDetail()
    },
    handleTick () {
      // TODO剔除玩家
      let data = this.tableData[0]
      let uId = data['val']
      console.log('待开发,踢玩家,需要新加接口,userId:', uId)
      this.$Message.error('踢号,待开发,请耐心等待!!!')
    },
    handleRechargeDetail () {
      getRechargeLogs(this.selectUserId, this.crtPage, this.pageSize).then((data) => {
        if (!data) {
          return
        }
        this.rechargeData = []
        let RechargeLogVO = getVO('RechargeLogVO')
        let pv = data.data.data
        let len = pv.data.length
        for (let i = 0; i < len; i++) {
          let vo = RechargeLogVO.decode(pv.data[i])
          vo.rechargeID = vo.rechargeID.toNumber()
          vo.time = vo.time.toNumber()
          vo.createTime = vo.createTime.toNumber()
          vo.totalPoints = vo.totalPoints.toNumber()
          this.rechargeData.push(vo)
        }
        console.log(this.rechargeData)
        this.rechargeModal = true
      })
    },
    lockAccount () {
      // TODO 待开发
      let data = this.tableData[0]
      let uId = data['val']
      console.log('待开发,userId:', uId)
      this.$Message.error('封号功能,待开发,请耐心等待!!!')
    }
  },
  computed: {
    tableColumns () {
      let cols = [
        {
          title: '参数名',
          width: 150,
          key: 'name'
        },
        {
          title: '值',
          key: 'val',
          render: (h, params) => {
            let data = this.tableData[params.index]
            console.log(data)
            if (params.index === 2) {
              return h('div', [
                h('Label', {
                  props: {
                    type: 'primary',
                    size: 'small'
                  },
                  style: {
                    marginRight: '50px'
                  }
                }, data['val']),
                h('Button', {
                  props: {
                    type: 'primary',
                    size: 'small'
                  },
                  style: {
                    marginRight: '10px'
                  },
                  on: {
                    click: () => {
                      this.handleTick()
                    }
                  }
                }, '踢下线'),
                h('Button', {
                  props: {
                    type: 'primary',
                    size: 'small'
                  },
                  style: {
                    marginRight: '5px'
                  },
                  on: {
                    click: () => {
                      this.lockAccount()
                    }
                  }
                }, '封号')
              ])
            } else if (params.index === 14) {
              return h('div', [
                h('Label', {
                  props: {
                    type: 'primary',
                    size: 'small'
                  },
                  style: {
                    marginRight: '50px'
                  }
                }, data['val']),
                h('Button', {
                  props: {
                    type: 'primary',
                    size: 'small'
                  },
                  style: {
                    marginRight: '5px'
                  },
                  on: {
                    click: () => {
                      this.handleRechargeDetail()
                    }
                  }
                }, '详细信息')
              ])
            } else {
              return h('div', [
                h('Label', {
                  props: {
                    type: 'primary',
                    size: 'small'
                  },
                  style: {
                    marginRight: '10px'
                  }
                }, data['val'])
              ])
            }
          }
        }
      ]
      return cols
    },
    rechargeColumns () {
      let cols = [
        {
          title: '充值ID',
          key: 'rechargeID'
        },
        {
          title: '充值时间',
          key: 'time'
        },
        {
          title: '玩家ID',
          key: 'userID'
        },
        {
          title: '订单号',
          key: 'orderID'
        },
        {
          title: '产品Id',
          key: 'productId'
        },
        {
          title: '金额',
          key: 'amount'
        },
        {
          title: '金币',
          key: 'gold'
        },
        {
          title: '充值渠道',
          key: 'repayAnything'
        },
        {
          title: '签名',
          key: 'sign'
        },
        {
          title: '备忘录',
          key: 'memo'
        },
        {
          title: '剩余金币',
          key: 'points'
        },
        {
          title: '创建时间',
          key: 'createTime'
        },
        {
          title: '渠道号',
          key: 'gameOperator'
        },
        {
          title: '是否成功',
          key: 'IsSuccess'
        },
        {
          title: '总金币',
          key: 'totalPoints'
        },
        {
          title: '等级',
          key: 'level'
        },
        {
          title: 'sdkOrderId',
          key: 'sdkOrderId'
        },
        {
          title: 'vip等级',
          key: 'vipLevel'
        },
        {
          title: '充值等级',
          key: 'rechargeLevel'
        }
      ]
      return cols
    }
  }
}

</script>

<style scoped>
.log-str{
  font-size: 14px;
  margin-bottom: 2px;
}
.content{
  min-height: 460px;
}
.bottom-page{
  margin-top: 5px;
  margin-bottom: 10px;
  float: right;
}
.role_base_info {
    width: 500px;
  }
</style>
